import binascii
import socket
import struct
import sys
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = socket.gethostbyname(socket.gethostname())
server_address = (host, 3333)
sock.connect(server_address)
values = (1, 'ab', 2.7)
packer = struct.Struct('I 2s f')
packed_data = packer.pack(*values)
print 'values =', values
try:
    # Send data
    print >>sys.stderr, 'sending %r' % binascii.hexlify(packed_data)
    sock.send(packed_data)
finally:
    print >>sys.stderr, 'closing socket'
    sock.close()
